﻿@using WSS.hameduconn.Business.Dto;

@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_LayoutAdmin.cshtml";
}

@{
    List<RegistrationsDto> lstRegistrations = new List<RegistrationsDto>();
    lstRegistrations = (List<RegistrationsDto>)ViewBag.RegistrationList;    
}

<div id="modalDeleted" class="modal fade" style="">
    <div class="modal-dialog">
        <div class="modal-content">
            <!-- dialog body -->
            <div class="modal-body">
                <button type="button" class="close" data-dismiss="modal">&times;</button>
                <span class="msgModal"></span>
            </div>
            <!-- dialog buttons -->
            <div class="modal-footer">
                <button type="button" class="btn btn-primary" onclick="javascript: deletedRegistrationExactly();">OK</button>
                <button type="button" class="btn" data-dismiss="modal">Cancel</button>
            </div>
        </div>
    </div>
</div>

<div class="container-fluid text-right">
    <div class="col-sm-12">
        <input type="submit" class="btn btn-success" id="btnCreateNewAccount" value="Create new account" />
    </div>
</div>

<div class="container-fluid">
    <table class="table table-striped">
        <thead>
            <tr>
                <th>#</th>
                <th>Username</th>
                <th>Password</th>                
                <th>First Name</th>
                <th>Last Name</th>
                <th>Email</th>
                <th>Street</th>
                <th>City</th>
                <th>State</th>
                <th>Credit Card No</th>
                <th>CVS</th>
                <th></th>
            </tr>
        </thead>
        <tbody>
            @for (int i = 0; i < lstRegistrations.Count; i++) { 
            <tr>
                <td>@(i+1)</td>
                <td>@lstRegistrations[i].Username</td>
                <td>@lstRegistrations[i].Password</td>
                <td>@lstRegistrations[i].FirstName</td>
                <td>@lstRegistrations[i].LastName</td>
                <td>@lstRegistrations[i].Email</td>
                <td>@lstRegistrations[i].Street</td>
                <td>@lstRegistrations[i].City</td>
                <td>@lstRegistrations[i].State</td>
                <td>@lstRegistrations[i].CreditCardNo</td>
                <td>@lstRegistrations[i].CVS</td>
                <td>
                    <a href="javascript: editedRegistration('@lstRegistrations[i].Id');"><img src="~/Images/items/edit-item.png" /></a>
                    <a href="javascript: deletedRegistration('@lstRegistrations[i].Id', '@lstRegistrations[i].Username');"><img src="~/Images/items/delete-item.png" /></a>
                </td>
            </tr>
            }
        </tbody>
    </table>
</div>

<script>
    function showModal(){
        $('#modalDeleted').modal('show');
    }
    function hideModal(){
        $('#modalDeleted').modal('hide');
    }

    function editedRegistration(id) {
        window.location.href = '@Url.Content("~/Admin/EditUser?id=")' + id + '&UserId=' + '@ViewBag.UserId' + '&UserName=' + '@ViewBag.UserName';
    }

    var UserId;
    function deletedRegistrationExactly() {
        window.location.href = '@Url.Content("~/Admin/DeletedUser?id=")' + UserId + '&UserId=' + '@ViewBag.UserId' + '&UserName=' + '@ViewBag.UserName';
    }
    function deletedRegistration(id, userName) {
        UserId = id;
        $('#modalDeleted').modal('show');
        $('#modalDeleted span.msgModal').html('Are you want to delete: ' + userName);        
    }

    $(function () {
        
        //$('#modalDeleted').on('shown.bs.modal', function () {
        //    alert('show');
        //});
        //$('#modalDeleted').on('hide.bs.modal', function () {
        //    alert('hide');
        //});

        $('#btnCreateNewAccount').click(function () {
            window.location.href = '@Url.Content("~/Admin/CreateUser?UserId=")' + '@ViewBag.UserId' + '&UserName=' + '@ViewBag.UserName';
        });
    });

</script>